function [base, base_sm] = CalcBaseImage (stack, base_inds, sp_filter)
% calculate a baseline image
% base_inds specify the baseline frames as logical indices or real numbers.
% sp_filter: spatial low-pass filter
%   it this parameter is omitted, base_sm=0.
% base: baseline image without smoothing
% base_sm: baseline image with smoothing

base = mean(stack(:,:,base_inds), 3);

if (nargin >= 3)
    base_sm = Filter2Modified(sp_filter, base);
else
    base_sm = 0;
end